package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GenerateRule;
import com.ruoyi.system.service.IGenerateRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生成规则Controller
 *
 * @author chenming
 * @date 2024-10-16
 */
@RestController
@RequestMapping("/system/generateRule")
public class GenerateRuleController extends BaseController
{
    @Autowired
    private IGenerateRuleService generateRuleService;

    /**
     * 查询生成规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:generateRule:list')")
    @GetMapping("/list")
    public TableDataInfo list(GenerateRule generateRule)
    {
        startPage();
        List<GenerateRule> list = generateRuleService.selectGenerateRuleList(generateRule);
        return getDataTable(list);
    }

    /**
     * 导出生成规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:generateRule:export')")
    @Log(title = "生成规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GenerateRule generateRule)
    {
        List<GenerateRule> list = generateRuleService.selectGenerateRuleList(generateRule);
        ExcelUtil<GenerateRule> util = new ExcelUtil<GenerateRule>(GenerateRule.class);
        util.exportExcel(response, list, "生成规则数据");
    }

    /**
     * 获取生成规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:generateRule:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return success(generateRuleService.selectGenerateRuleByRuleId(ruleId));
    }

    /**
     * 新增生成规则
     */
    @PreAuthorize("@ss.hasPermi('system:generateRule:add')")
    @Log(title = "生成规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GenerateRule generateRule)
    {
        return toAjax(generateRuleService.insertGenerateRule(generateRule));
    }

    /**
     * 修改生成规则
     */
    @PreAuthorize("@ss.hasPermi('system:generateRule:edit')")
    @Log(title = "生成规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GenerateRule generateRule)
    {
        return toAjax(generateRuleService.updateGenerateRule(generateRule));
    }

    /**
     * 删除生成规则
     */
    @PreAuthorize("@ss.hasPermi('system:generateRule:remove')")
    @Log(title = "生成规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(generateRuleService.deleteGenerateRuleByRuleIds(ruleIds));
    }
}
